package org.wlgzs.website.wlgzsoffice.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 过滤字符编码
 */
@Slf4j
@WebFilter(filterName="AllFilter",urlPatterns="/*")
public class AllFilter implements Filter {

    @Override  
    public void destroy() {  
          log.info("过滤器销毁");
    }  
  
    @Override  
    public void doFilter(ServletRequest req, ServletResponse res,
                         FilterChain chain) throws IOException, ServletException {
        chain.doFilter(req, res);
        //这么做是为了设置字符编码只限于post的
        req.setCharacterEncoding("UTF-8");
		res.setContentType("text/html;charset=utf8");
        HttpServletRequest request = (HttpServletRequest) req;
        log.info(request.getRequestURI()+" "+request.getMethod());
    }  
  
    @Override  
    public void init(FilterConfig arg0) throws ServletException {
        log.info("过滤器初始化");
    }  
}  
